package com.hlm.demo.service.cost;

import com.hlm.demo.entity.CostInfo;
import com.hlm.demo.mapper.CostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资费模块
 *
 * @author Ric
 */
@Service
public class CostService implements ICostService {

    @Autowired
    CostMapper costMapper;


    @Override
    public List<CostInfo> costCheck(String order, Integer page, Integer count) {

        Map<String, Object> costMap = new HashMap<>();
        // TODO 参数判断
        page = (page - 1) * count;

        costMap.put("order", order);
        costMap.put("page", page);
        costMap.put("count", count);

        return costMapper.costChecker(costMap);
    }

    @Override
    public Integer costTotalCheck() {
        return costMapper.costTotalChecker();
    }


    /**
     * 资费修改
     *
     * @param costInfo
     */
    @Override
    public void costModify(CostInfo costInfo) {

        System.out.println(costInfo);
        Map<String, Object> costMap = new HashMap<>();

        Integer costId = costInfo.getCostId();

        String costName = costInfo.getCostName();
        Integer baseDuration = costInfo.getBaseDuration();
        Integer baseCost = costInfo.getBaseCost();
        Integer unitCost = costInfo.getUnitCost();
        String descr = costInfo.getDescr();
        String costType = costInfo.getCostType();

        // 资费 id
        costMap.put("costId", costId);
        // 资费名称 -> 非空判断
        if (!costName.trim().equals("")) {
            costMap.put("costName", costName);
        }
        // 基本时长
        costMap.put("baseDuration", baseDuration);
        // 基本费用
        costMap.put("baseCost", baseCost);
        // 单位费用
        costMap.put("unitCost", unitCost);

        // 资费描述 -> 非空判断
        if (!descr.trim().equals("")) {
            costMap.put("descr", descr);
        }

        // 资费类型
        costMap.put("costType", costType);

        costMapper.costModifier(costMap);

    }

    /**
     * 资费启用暂停删除
     *
     * @param costId
     * @param costStatus
     */
    @Override
    public void costSwitch(String costId, Integer costStatus) {

        Map<String, Object> costMap = new HashMap<>();
        // TODO 判断
        costMap.put("costId", costId);
        costMap.put("costStatus", costStatus);

        costMapper.costSwitcher(costMap);
    }

    @Override
    public void costAdd(CostInfo costInfo) {

        Map<String, Object> costMap = new HashMap<>();

        // TODO 判断
        String costName = costInfo.getCostName();
        if (!costName.trim().equals("")) {
            costMap.put("costName", costName);
        }

        costMap.put("baseDuration", costInfo.getBaseDuration());
        costMap.put("baseCost", costInfo.getBaseCost());
        costMap.put("unitCost", costInfo.getUnitCost());
        costMap.put("costStatus", 1);
        costMap.put("descr", costInfo.getDescr());
        String costType = costInfo.getCostType();
        if (costType.equals("c") || costType.equals("t") || costType.equals("m")) {
            costMap.put("costType", costInfo.getCostType());
        }

        costMapper.costAdder(costMap);

    }
}
